﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QRCodeTools {
    public partial class BorderRectangle : Panel {

        public BorderRectangle() {
            SetStyle(ControlStyles.SupportsTransparentBackColor
              | ControlStyles.UserPaint
              | ControlStyles.AllPaintingInWmPaint
              | ControlStyles.Opaque, true);
            
            InitializeComponent();
        }

        public BorderRectangle(IContainer container) {
            container.Add(this);

            SetStyle(ControlStyles.SupportsTransparentBackColor
              | ControlStyles.UserPaint
              | ControlStyles.AllPaintingInWmPaint
              | ControlStyles.Opaque, true);

            InitializeComponent();
        }
        protected override CreateParams CreateParams {
            get {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x00000020; // 开启 WS_EX_TRANSPARENT,使控件支持透明
                return cp;
            }
        }

        private Color _BorderColor = Color.Black;
        [Browsable(true), Description("边框颜色"), Category("自定义分组")]
        public Color BorderColor {
            get { return _BorderColor; }
            set {
                _BorderColor = value;
                Invalidate();
            }
        }

        private int _BorderSize = 1;

        [Browsable(true), Description("边框粗细"), Category("自定义分组")]
        public int BorderSize {
            get { return _BorderSize; }
            set {
                _BorderSize = value;
                Invalidate();
            }
        }

        /// <summary>
        /// 重写OnPaint方法
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);
            ControlPaint.DrawBorder(e.Graphics,
                            ClientRectangle,
                            _BorderColor,
                            _BorderSize,
                            ButtonBorderStyle.Solid,
                            _BorderColor,
                            _BorderSize,
                            ButtonBorderStyle.Solid,
                           _BorderColor,
                            _BorderSize,
                            ButtonBorderStyle.Solid,
                            _BorderColor,
                            _BorderSize,
                            ButtonBorderStyle.Solid);
        }
    }
}
